<template>
  <h2 class="text-xl font-bold mb-4">签到记录</h2>

  <el-table :data="attendanceHistory" style="width: 100%">
    <el-table-column prop="createdByName" label="发布人" />
    <el-table-column prop="des" label="签到描述" />
    <el-table-column prop="createdTime" label="发布时间" />
    <el-table-column prop="status" label="状态">
      <template #default="{ row }">
        <el-tag v-if="row.signInUsers" type="success"> 已签到 </el-tag>
        <el-button
          v-else
          size="small"
          type="primary"
          @click="handleSign(row.id)"
        >
          点击签到
        </el-button>
      </template>
    </el-table-column>
    <el-table-column prop="signInTime" label="签到时间"/>
  </el-table>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { request } from "../../../utils/request";
import { doSignIn, getNoSignIn, signIn } from "../../../api/modules/course";
import { ElMessage } from "element-plus";

const attendanceHistory = ref([]);

function getSign() {
  request({
    fn: getNoSignIn,
    params: [],
    success(res) {
      attendanceHistory.value = res.data || [];
    },
  });
}

getSign();

function handleSign(id) {
  request({
    fn: doSignIn,
    params: [id],
    success(res) {
      ElMessage.success("签到成功");
      getSign();
    },
  });
}
</script>
<style scoped lang="scss"></style>
